package com.ymttest.business.service;

import java.beans.BeanInfo;
import java.beans.IntrospectionException;
import java.beans.Introspector;
import java.beans.PropertyDescriptor;
import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.lang.reflect.Method;
import java.nio.charset.Charset;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.Map;
import java.util.Random;

import org.apache.http.client.ClientProtocolException;

import com.google.gson.JsonObject;
import com.google.gson.reflect.TypeToken;
import com.shop2cn.iapi.wxcomponent.parameter.AppStatusEnum;
import com.shop2cn.iapi.wxcomponent.parameter.ApplyChargeBean;
import com.shop2cn.iapi.wxcomponent.parameter.ConfirmAuditMchAppBean;
import com.shop2cn.iapi.wxcomponent.parameter.ConfirmAuthorizationBean;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchAppAllStatusBean;
import com.shop2cn.iapi.wxcomponent.parameter.NofifyChargeStatusBean;
import com.shop2cn.iapi.wxcomponent.parameter.PayChannelStatusEnum;
import com.shop2cn.iapi.wxcomponent.parameter.GetMchChargeStatusAndMoneyBean;
import com.shop2cn.iapi.wxcomponent.parameter.RemarkBean;
import com.shop2cn.iapi.wxcomponent.service.ApplyChargeCall;
import com.shop2cn.iapi.wxcomponent.service.ConfirmAuditMchAppCall;
import com.shop2cn.iapi.wxcomponent.service.ConfirmAuthorizationCall;
import com.shop2cn.iapi.wxcomponent.service.GetMchAppAllStatusCall;
import com.shop2cn.iapi.wxcomponent.service.NofifyChargeStatusCall;
import com.shop2cn.iapi.wxcomponent.service.GetMchChargeStatusAndMoneyCall;
import com.shop2cn.iapi.wxcomponent.service.NofifyChargeStatusCall;
import com.shop2cn.iapi.wxcomponent.service.RemarkCall;
import com.shop2cn.wxcomponent.parameter.AppCallBackBean;
import com.shop2cn.wxcomponent.parameter.AuthorizationCallBackBean;
import com.shop2cn.wxcomponent.service.AppCallBackCall;
import com.shop2cn.wxcomponent.service.AuthorizationCallBackCall;
import com.ymt.base.BaseBean;
import com.ymt.core.tool.FormatUtil;
import com.ymt.core.tool.Logger;
import com.ymttest.database.model.Mchapp;
import com.ymttest.database.model.Platformconfig;
import com.ymttest.database.sqlwapper.godmch.DefGodMchWapper;
import com.ymttest.utils.TestDataManager;
import com.ymttest.utils.YMTDateUtil;
import com.ymttest.utils.wxmini.aes.AesException;
import com.ymttest.utils.wxmini.aes.SHA1;
import com.ymttest.utils.wxmini.aes.WXBizMsgCrypt;

/************************************************************************************
 * @File name :WxComponentService.java
 * @Author : zhouyi
 * @Date : 2019年12月18日
 * @Copyright : 洋码头
 * ConfirmAuthorization 商户确认授权-插入商户数据mchapp ->
 * AuthorizationCallBack 授权回调 更新 AppStatus 已授权->
 * ConfirmAuditMchApp 小程序提审 mock - 上传代码状态 -提交审核状态-是否有release模板-类目允许列表-relase发布是否成功  ->
 * AppCallBackAuditSuccess 小程序提审成功通知->
 * 
 * 
 ************************************************************************************/
public class WxComponentService {
	public static final String encodingAesKey = "vqiY9Hv1cWUV1PS6yIvMQ3Giv5n8SdK6flLCzDBlXdA";
	public static final String token = "LLq1TmfQzhRKFBrZ";
	public static double defmoney=0.01;
	/**
	 * 修改备注
	 * @param mark
	 * @param mchid
	 * @throws ClientProtocolException
	 * @throws IOException
	 */
	public static void Remark(String mark,Integer mchid) throws ClientProtocolException, IOException {
		RemarkBean remarkBean=new RemarkBean();
		RemarkCall remarkCall=new RemarkCall();
		remarkBean.setMark(mark);
		remarkBean.setMchId(mchid);
		remarkCall.setData(remarkBean);
		remarkCall.callService();	
	}
	/**
	 * app提审回调成功
	 * @param mchid 商家id
	 * @param appid appid
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException
	 * @throws AesException
	 */
	public static void AppCallBackAuditSuccess(Integer mchid,String appid) throws ClientProtocolException, IOException, InterruptedException, AesException {
		String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
		AppCallBackCall AppCallBackCall;
		AppCallBackBean AppCallBackBean=new AppCallBackBean();
		AppCallBackBean.setToUserName("touname");
		AppCallBackBean.setFromUserName("funame");
		AppCallBackBean.setCreateTime(Long.valueOf(timestamp));
		AppCallBackBean.setSuccTime(Long.valueOf(timestamp));
		AppCallBackBean.setEvent("weapp_audit_success");
		AppCallBackBean.setMsgType("event");
		Map sendinfo=WxComponentService.getAppCallBackSend(AppCallBackBean);
//		Logger.debug(sendinfo);
		String signature=sendinfo.get("signature").toString();
		String mingwen=sendinfo.get("mingwen").toString();
		String nonce=sendinfo.get("nonce").toString();
		//api/{APPID}/callback?timestamp=1575973810&nonce=155395418&encrypt_type=aes&msg_signature=39e94b7cf31b636a010c0894918d4f0442f741f3
		String opurl2="api/"+appid+"/callback?timestamp="+timestamp+"&nonce="+nonce+"&encrypt_type=aes&msg_signature="+signature;
		AppCallBackCall=new AppCallBackCall(opurl2);
		AppCallBackCall.setData(mingwen);
		AppCallBackCall.callService();	
	}
	
	/**
	 * 小程序提审
	 * @return
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static Map ConfirmAuditMchApp(Integer mchid) throws ClientProtocolException, IOException {
		ConfirmAuditMchAppBean confirmauditmchappBean=new ConfirmAuditMchAppBean();
		ConfirmAuditMchAppCall confirmauditmchappCall=new ConfirmAuditMchAppCall();
		confirmauditmchappBean.setMchId(mchid);
		confirmauditmchappCall.setData(confirmauditmchappBean);
		Map m=new HashMap();
//		mock:mock-enable
		m.put("mock", "mock-enable");
		m.put("mockId-1", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-1", "wxcomponent-uploadCode-Normal");
		m.put("mockId-2", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-2", "wxcomponent-submitAudit-Normal");
		m.put("mockId-3", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-3", "wxcomponent-getTemplateList-Normal");
		m.put("mockId-4", TestDataManager.getRandomUUID().toString());
		m.put("mockApi-4", "wxcomponent-getCategory-Normal");
//		m.put("mockId-5", TestDataManager.getRandomUUID().toString());
//		m.put("mockApi-5", "wxcomponent-release-Normal");
		String auditid=TestDataManager.getRandomNum(6);
		m.put("mockParam-1-code",0); 
		m.put("mockParam-2-auditid",auditid);
		PayGateWayCallService.addMock(confirmauditmchappCall, m);
		confirmauditmchappCall.callService();
		return m;
	}
	//删除预制数据
	//DefGodMchWapper.deleteMchappByMchid(confirmauthorizationBean.getMchId());
	/**
	 * 删除存量数据
	 * @param mchid
	 * @throws InterruptedException
	 */
	public static void deleteMchinfo(Integer mchid) throws InterruptedException {
		new DefGodMchWapper().deleteMchappByMchid(mchid);
	}
	/**
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * 
	 */
	/**
	 * 授权回调
	 * @param appid
	 * @param InfoType "authorized"1 unauthorized 0
	 * @throws ClientProtocolException
	 * @throws IOException
	 * @throws InterruptedException 
	 * @throws AesException 
	 */
	public static void AuthorizationCallBack(String appid,String InfoType) throws ClientProtocolException, IOException, InterruptedException, AesException {
		AuthorizationCallBackBean authorizationcallbackBean=new AuthorizationCallBackBean();
		AuthorizationCallBackCall authorizationcallbackCall;
		String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
		Platformconfig platf = new DefGodMchWapper().selectPlatformconfigByExample().get(0);
		authorizationcallbackBean.setAppId(platf.getPlatformAppId());
		authorizationcallbackBean.setCreateTime(Long.valueOf(timestamp));
		authorizationcallbackBean.setInfoType(InfoType);
		authorizationcallbackBean.setAuthorizerAppid(appid.toString());
		Map sendinfo=WxComponentService.getAuthorizationcallbackSend(authorizationcallbackBean);
//		Logger.debug(sendinfo);
		String signature=sendinfo.get("signature").toString();
		String mingwen=sendinfo.get("mingwen").toString();
		String nonce=sendinfo.get("nonce").toString();
		String opurl2="api/authorizeCallBackNotice?timestamp="+timestamp+"&nonce="+nonce+"&encrypt_type=aes&msg_signature="+signature;
		authorizationcallbackCall=new AuthorizationCallBackCall(opurl2);
		authorizationcallbackCall.setData(mingwen);
		authorizationcallbackCall.callService();	
	}
	/**
	 * 商户确认授权-插入商户数据 "appStatus":1
	 * @param mchid
	 * @return appid 如果不成功返回""
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static String  ConfirmAuthorization(Integer mchid) throws ClientProtocolException, IOException{
		ConfirmAuthorizationBean confirmauthorizationBean=new ConfirmAuthorizationBean();
		ConfirmAuthorizationCall confirmauthorizationCall=new ConfirmAuthorizationCall();
		confirmauthorizationBean.setMchId(mchid);
		confirmauthorizationBean.setAuthorizationCode("1234");
		confirmauthorizationCall.setData(confirmauthorizationBean);
		Map m=new HashMap();
//		mock:mock-enable
		m.put("mock", "mock-enable");
//		mockId-1:wxcomponent-getAuthInfo-11
		m.put("mockId-1", TestDataManager.getRandomUUID().toString());
//		mockApi-1:wxcomponent-getAuthInfo-Normal
		m.put("mockApi-1", "wxcomponent-getAuthInfo-Normal");
//		mockId-2:wxcomponent-getAppInfo-11
		m.put("mockId-2", TestDataManager.getRandomUUID().toString());
//		mockApi-2:wxcomponent-getAppInfo-Normal
		m.put("mockApi-2", "wxcomponent-getAppInfo-Normal");
		String atoken=TestDataManager.getRandomNum(10);
		String appid=TestDataManager.getRandomNum(10);
		String rtoken=TestDataManager.getRandomNum(10);
		m.put("mockParam-1-authorizerAccessToken",atoken);
		m.put("mockParam-1-authorizerAppid",appid);
		m.put("mockParam-1-authorizerRefreshToken",rtoken);
		
		String nickName=TestDataManager.getRandomNum(10);
		String headImg=TestDataManager.getRandomNum(10);
		String principalName=TestDataManager.getRandomNum(10);
//	    "nick_name":"${nickName=nick_name}",
		m.put("mockParam-2-nickName",nickName);
//	    "head_img":"${headImg=head_img}",
		m.put("mockParam-2-headImg",headImg);
//	    "principal_name":"${principalName=principal_name}",
		m.put("mockParam-2-principalName",principalName);
		PayGateWayCallService.addMock(confirmauthorizationCall, m);
		confirmauthorizationCall.callService();	
		if("200".equals(confirmauthorizationCall.getString("code"))) {
			return appid;
		}
		return "";
	}
	
	
	/**
	 * 商户确认授权-插入商户数据 "appStatus":1 设置appid
	 * @param mchid
	 * @return appid 如果不成功返回""
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static boolean  ConfirmAuthorization(Integer mchid,String appid) throws ClientProtocolException, IOException{
		ConfirmAuthorizationBean confirmauthorizationBean=new ConfirmAuthorizationBean();
		ConfirmAuthorizationCall confirmauthorizationCall=new ConfirmAuthorizationCall();
		confirmauthorizationBean.setMchId(mchid);
		confirmauthorizationBean.setAuthorizationCode("1234");
		confirmauthorizationCall.setData(confirmauthorizationBean);
		Map m=new HashMap();
//		mock:mock-enable
		m.put("mock", "mock-enable");
//		mockId-1:wxcomponent-getAuthInfo-11
		m.put("mockId-1", TestDataManager.getRandomUUID().toString());
//		mockApi-1:wxcomponent-getAuthInfo-Normal
		m.put("mockApi-1", "wxcomponent-getAuthInfo-Normal");
//		mockId-2:wxcomponent-getAppInfo-11
		m.put("mockId-2", TestDataManager.getRandomUUID().toString());
//		mockApi-2:wxcomponent-getAppInfo-Normal
		m.put("mockApi-2", "wxcomponent-getAppInfo-Normal");
		String atoken=TestDataManager.getRandomNum(10);
		String rtoken=TestDataManager.getRandomNum(10);
		m.put("mockParam-1-authorizerAccessToken",atoken);
		m.put("mockParam-1-authorizerAppid",appid);
		m.put("mockParam-1-authorizerRefreshToken",rtoken);
		
		String nickName=TestDataManager.getRandomNum(10);
		String headImg=TestDataManager.getRandomNum(10);
		String principalName=TestDataManager.getRandomNum(10);
//	    "nick_name":"${nickName=nick_name}",
		m.put("mockParam-2-nickName",nickName);
//	    "head_img":"${headImg=head_img}",
		m.put("mockParam-2-headImg",headImg);
//	    "principal_name":"${principalName=principal_name}",
		m.put("mockParam-2-principalName",principalName);
		PayGateWayCallService.addMock(confirmauthorizationCall, m);
		confirmauthorizationCall.callService();	
		if("200".equals(confirmauthorizationCall.getString("code"))) {
			return true;
		}
		return false;
	}
	
	
	/**
	 * 商户取消授权-插入商户数据 "appStatus":0
	 * @param mchid
	 * @return appid 如果不成功返回""
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 * @throws InterruptedException 
	 */
	public static void  CancelAuthorization(Integer mchid) throws Exception{
		
		AuthorizationCallBackBean authorizationcallbackBean = new AuthorizationCallBackBean();
		AuthorizationCallBackCall authorizationcallbackCall = new AuthorizationCallBackCall();
        String timestamp=String.valueOf(YMTDateUtil.getDate().getTime()/1000);
        WxComponentService.deleteMchinfo(mchid);
		String appid = WxComponentService.ConfirmAuthorization(mchid);
		WxComponentService.AuthorizationCallBack(appid, "authorized");
		Platformconfig platf = new DefGodMchWapper().selectPlatformconfigByExample().get(0);
		authorizationcallbackBean.setAppId(platf.getPlatformAppId());
		authorizationcallbackBean.setCreateTime(Long.valueOf(timestamp));
		authorizationcallbackBean.setInfoType("unauthorized");
		authorizationcallbackBean.setAuthorizerAppid(appid);
		Map sendinfo=WxComponentService.getAuthorizationcallbackSend(authorizationcallbackBean);
//		Logger.debug(sendinfo);
		String signature=sendinfo.get("signature").toString();
		String mingwen=sendinfo.get("mingwen").toString();
		String nonce=sendinfo.get("nonce").toString();
		String opurl2="api/authorizeCallBackNotice?timestamp="+timestamp+"&nonce="+nonce+"&encrypt_type=aes&msg_signature="+signature;
		authorizationcallbackCall=new AuthorizationCallBackCall(opurl2);
		authorizationcallbackCall.setData(mingwen);
		authorizationcallbackCall.callService();	
		Logger.verifyEquals("ok", authorizationcallbackCall.getReturnData(), "验证返回");
		int size = new DefGodMchWapper().selectMchappByExample(mchid).size();
		Logger.verifyEquals(0,size, "验证AppStatus");
	}
	/**
	 * 获取回调报文
	 * @param encrypt 加密报文
	 * @param appid 平台appid
	 * @return
	 */
	public static String getAuthorizationcallbackSend(String encrypt,String appid) {
		String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n"
				+ "<AppId><![CDATA[%2$s]]></AppId>\n"+
			 "</xml>";
		return String.format(format, encrypt,appid);
	}
	/**
	 * @param encrypt
	 * @param toname
	 * @return
	 */
	public static String getAppcallbackSend(String encrypt,String toname) {
		String format = "<xml>\n" + "<Encrypt><![CDATA[%1$s]]></Encrypt>\n"
				+ "<ToUserName><![CDATA[%2$s]]></ToUserName>\n"+
			 "</xml>";
		return String.format(format, encrypt,toname);
	}
	/**
	 * @param authorizationcallbackBean
	 * @return  m.put("nonce", nonce);
		m.put("encrypt", encrypt);
		m.put("mingwen", mingwen);
		m.put("timestamp", timestamp);
		m.put("signature", signature);
		
	 * @throws InterruptedException 
	 * @throws AesException 
	 */
	public static Map getAuthorizationcallbackSend(AuthorizationCallBackBean authorizationcallbackBean) throws InterruptedException, AesException {
		Map m =new HashMap<>();
		String xmlMW=WxComponentService.beanToXmlString(authorizationcallbackBean);
		Platformconfig platf = new DefGodMchWapper().selectPlatformconfigByExample().get(0);
		Long timestamp=authorizationcallbackBean.getCreateTime();
		String nonce=TestDataManager.getRandomNum(9);
		String RandomStr=WxComponentService.getRandomStr();
		String encrypt = WxComponentService.getEncryptMsg(xmlMW, timestamp.toString(), nonce,RandomStr,platf.getPlatformAppId());
		String signature = WxComponentService.getSign(encrypt, timestamp.toString(), nonce,RandomStr,platf.getPlatformAppId());
		String mingwen=WxComponentService.getAuthorizationcallbackSend(encrypt, platf.getPlatformAppId());
		m.put("nonce", nonce);
		m.put("encrypt", encrypt);
		m.put("mingwen", mingwen);
		m.put("timestamp", timestamp);
		m.put("signature", signature);
		return m;
	}
	/**
	 * 获取随机
	 * @return
	 */
	public static String getRandomStr() {
		String base = "ABCDEFGHIJKLMNOPQRSTUVWXYZabcdefghijklmnopqrstuvwxyz0123456789";
		Random random = new Random();
		StringBuffer sb = new StringBuffer();
		for (int i = 0; i < 16; i++) {
			int number = random.nextInt(base.length());
			sb.append(base.charAt(number));
		}
		return sb.toString();
	}
	
	/**
	 * 小程序申请付费
	 * @return
	 */
	public static void ApplyCharge(int mchid) {
		ApplyChargeBean applychargeBean = new ApplyChargeBean();
		ApplyChargeCall applychargeCall = new ApplyChargeCall();
		
		applychargeBean.setUserId(mchid);
		applychargeBean.setMchId(mchid);
		applychargeBean.setChargeIp(TestDataManager.getRandomIp());
		applychargeBean.setCallbackUrl("http://www.ymatou.com");
		applychargeCall.setData(applychargeBean);
		try {
			applychargeCall.callService();
		} catch (Exception e) {
			// TODO 自动生成的 catch 块
			e.printStackTrace();
		} 
		Logger.verifyEquals("200", applychargeCall.getString("code"), "验证code");
	}
	
	
	
	/**
	 * 解密密文
	 * @param mingwen
	 * @param appid
	 * @return
	 * @throws AesException
	 */
	public static String decryptMsg(String mingwen,String appid) throws AesException {
		String result2 = new WXBizMsgCrypt(WxComponentService.token, WxComponentService.encodingAesKey, appid).decrypt(mingwen);
		return result2;
	}
	/**
	 * 获取加密
	 * @param xmlMW
	 * @param timeStamp
	 * @param nonce
	 * @param random
	 * @throws AesException 
	 */
	public static String getEncryptMsg(String xmlMW, String timeStamp, String nonce,String random ,String PlatformAppId) throws AesException {
		WXBizMsgCrypt pc = new WXBizMsgCrypt(WxComponentService.token, WxComponentService.encodingAesKey, PlatformAppId);
		String encrypt = pc.encrypt(random, xmlMW);
		return encrypt;
	}
	/**
	 * 返回签名
	 * @param xmlMW
	 * @param timeStamp
	 * @param nonce
	 * @param random
	 * @param PlatformAppId
	 * @return
	 * @throws AesException
	 */
	public static String getSign(String encrypt, String timeStamp, String nonce,String random ,String PlatformAppId) throws AesException {
		WXBizMsgCrypt pc = new WXBizMsgCrypt(WxComponentService.token, WxComponentService.encodingAesKey, PlatformAppId);
		String signature = SHA1.getSHA1(token, timeStamp, nonce, encrypt);
		return signature;
	}
	/**bean转换成xml
	 * @param bb
	 * @return
	 */
	public static String beanToXmlString(BaseBean bb) {
		Map<String,String> m = (Map<String,String>) FormatUtil.GSONToObject(FormatUtil.beanToGSONString(bb),new TypeToken<Map<String, String>>() {}.getType());
		String p = "<xml>";
		try {
			if (!(m == null)) {
				Iterator i = m.entrySet().iterator();
				while (i.hasNext()) {
					String obj = i.next().toString();
					int index = obj.indexOf("=");
					String propertyName = obj.substring(0, index);
					String value = obj.substring(index + 1, obj.length());
						p += "<"+propertyName + ">" + value.toString() + "</"+propertyName + ">" ;
					}
			}
		} catch (Exception e) {
			e.printStackTrace();
		}
		p += "</xml>";
		return p;
	}
	/**
	 * app审核信息回调报文
	 * @param appCallBackBean
	 * @return
	 * @throws InterruptedException
	 * @throws AesException
	 */
	public static Map getAppCallBackSend(AppCallBackBean appCallBackBean) throws InterruptedException, AesException {
		Map m =new HashMap<>();
		String xmlMW=WxComponentService.beanToXmlString(appCallBackBean);
		Platformconfig platf = new DefGodMchWapper().selectPlatformconfigByExample().get(0);
		Long timestamp=appCallBackBean.getCreateTime();
		String nonce=TestDataManager.getRandomNum(9);
		String RandomStr=WxComponentService.getRandomStr();
		String encrypt = WxComponentService.getEncryptMsg(xmlMW, timestamp.toString(), nonce,RandomStr,platf.getPlatformAppId());
		String signature = WxComponentService.getSign(encrypt, timestamp.toString(), nonce,RandomStr,platf.getPlatformAppId());
		String mingwen=WxComponentService.getAppcallbackSend(encrypt, appCallBackBean.getToUserName());
		m.put("nonce", nonce);
		m.put("encrypt", encrypt);
		m.put("mingwen", mingwen);
		m.put("timestamp", timestamp);
		m.put("signature", signature);
		return m;
	}
	
	
	
	
	/**
	 * 小程序查询白名单付费状态和金额
	 * @return 
	 * @return
	 */
	public static JsonObject GetMchChargeStatusAndMoney(int mchid) {
		GetMchChargeStatusAndMoneyBean Bean = new GetMchChargeStatusAndMoneyBean();
		GetMchChargeStatusAndMoneyCall Call = new GetMchChargeStatusAndMoneyCall();
		
		Bean.setMchId(mchid);
		Call.setData(Bean);
		try {
			Call.callService();
		} catch (Exception e) {
			e.printStackTrace();
		} 
		Logger.verifyEquals("200", Call.getString("code"), "验证code");
		JsonObject data = Call.getJsonObject().getAsJsonObject("data");
		return data;
	}
	
	
	/**
	 * 付费状态回调通知(确认付费)
	 * @return 
	 * @return
	 * @throws InterruptedException 
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static void ChargeNotify(int mchid) throws InterruptedException, ClientProtocolException, IOException {
		NofifyChargeStatusBean nofifychargestatusBean = new NofifyChargeStatusBean();
		NofifyChargeStatusCall nofifychargestatusCall = new NofifyChargeStatusCall();
		
		
		String tradingId = new DefGodMchWapper().selectMchChargeRecordIdByExample(mchid).get(0).getMchChargeRecordId();
		nofifychargestatusBean.setTradingId(tradingId);
		String formatTime = YMTDateUtil.getFormatTime(new Date(),"yyyyMMddHHmmss");
		nofifychargestatusBean.setPayTime(formatTime);
		nofifychargestatusBean.setPaymentId(formatTime);

		nofifychargestatusCall.setData(nofifychargestatusBean);
		nofifychargestatusCall.callService();
		Logger.verifyEquals("200", nofifychargestatusCall.getString("code"), "验证code");
	}
	
	
	
	/**
	 * 获取小程序所有状态
	 * @return 
	 * @return 
	 * @return
	 * @throws InterruptedException 
	 * @throws IOException 
	 * @throws ClientProtocolException 
	 */
	public static JsonObject GetMchAppAllStatus(int mchid) throws Exception {

		GetMchAppAllStatusBean getmchappallstatusBean = new GetMchAppAllStatusBean();
		GetMchAppAllStatusCall getmchappallstatusCall = new GetMchAppAllStatusCall();
		
		DefGodMchWapper DefGodMchWapper=new DefGodMchWapper();
		Mchapp defmchapp = DefGodMchWapper.selectMchappByExample(null).get(0);
		getmchappallstatusBean.setMchId(defmchapp.getMchId());
		getmchappallstatusCall.setData(getmchappallstatusBean);
		getmchappallstatusCall.callService();			
		Logger.verifyEquals("200", getmchappallstatusCall.getString("code"), "验证返回code");
		JsonObject ja = getmchappallstatusCall.getJsonObject().get("data").getAsJsonObject();
		return ja;
	}
	
	
}
